﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Koonsoft.HYCRM.BLL;
using Koonsoft.HYCRM.Model;

public partial class Accountant_CompanyBankMantissa2 : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            dropCurrency.Items.Add(new ListItem("支票账户", "99"));
            dropCurrency.Items.Add(new ListItem("储蓄账户", "98"));
            foreach (int v in Enum.GetValues(typeof(CurrencyEnum)))
            {
                if (v != 1)
                {
                    CurrencyEnum pStatus = (CurrencyEnum)v;
                    dropCurrency.Items.Add(new ListItem(RemarkAttribute.GetEnumRemark(pStatus), v.ToString()));
                }

            }

            Bind();
        }

    }

    private void Bind()
    {
        string company = Request.QueryString["CompanyID"];
        string orderid = Request.QueryString["orderid"];
        GridView1.DataSource = new AuditorsBLL().GetCompanyBankMantissa(company, orderid);
        GridView1.DataBind();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(TextBox1.Text.Trim()))
        {
            double i;
            try
            {
                i = Convert.ToDouble(TextBox1.Text.Trim());
            }
            catch (Exception)
            {
                AlertMsg("上期結餘格式错误");
                return;
            }

            string company = Request.QueryString["CompanyID"];
            string orderid = Request.QueryString["orderid"];
            try
            {

                new AuditorsBLL().AddOrUpdateCompanyBankMantissa(company, orderid, dropCurrency.SelectedValue, i);
                Bind();
            }
            catch (Exception)
            {
                AlertMsg("出现异常，请联系管理员");
                return;
            }
        }
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            int Currency = Convert.ToInt32(e.Row.Cells[0].Text);
            if (Currency == 99)
            {
                e.Row.Cells[0].Text = "支票账户";
            }
            else if (Currency == 98)
            {
                e.Row.Cells[0].Text = "储蓄账户";
            }
            else
            {
                CurrencyEnum CStatus = (CurrencyEnum)Currency;
                e.Row.Cells[0].Text = RemarkAttribute.GetEnumRemark(CStatus);
            }
        }

    }
}